//
//  HomePageViewController.m
//  carcareIOS
//
//  Created by tianxing on 16/3/14.
//  Copyright © 2016年 chezheng. All rights reserved.
//
#define heghtSection 7

#define cellNumbers  3
#define HEIGHT_ADVERTISE_VIEW (53 * __MAIN_RATIO_375)
#define HEICHT_ADVERTISE_VIEW_LINE (3)
#define HEIGHT_HEAD_DETAIL_VIEW (350)
#define HEIGHT_NOTIFITION_CELL (45)
#define HEIGHT_LINE_VIEW_SMALL (24)

#import "AdverticePageView.h"
#import "NetAdvertice.h"

#import "HomePageViewController.h"
#import "HeadDetailView.h"

#import "CommitInfoViewController.h"
#import "NetHomePage.h"

#import "HeadNotificationCell.h"
#import "HeadPageTableViewCell.h"
#import "HomePageH5Cell.h"

#import "MessageMgr.h"
#import "MessageViewController.h"
#import "RefreshMgr.h"

#import "HomePageMgr.h"
#import "RefreshMgr.h"
#import "MoneyTabViewController.h"

#import "HomeMoneyTipsView.h"
#import "AdverticePopView.h"
#import "AdverticePageModel.h"


@interface HomePageViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UITableView *tabelView;
//@property (nonatomic ,strong) HeadDetailView *headDetailView;
@property (nonatomic ,strong) UIImageView    *earnImageView;
@property (nonatomic ,strong) UIView         *line;                     //领取挣点上的线
@property (nonatomic ,copy)   NSString       *number;
@property (nonatomic ,strong) HeadPageTableViewCell *headPagecell;
@property (nonatomic , strong) AdverticePageView * adverticeView;
@property (nonatomic , copy) NSArray * adverticeDataArr;
@property (nonatomic ,assign) NSInteger policyStatus; //上传状态
@property (nonatomic ,assign) NSInteger  premium;     //今年保费

@property (nonatomic , assign) CGFloat totalScoreMoney;
//目前可以抵扣的挣点数对应的金额
@property (nonatomic , assign) CGFloat currScoreModey;

@property (nonatomic , strong) RefreshMgr *refreshMgr;

@property (nonatomic , assign) CGFloat oldLineViewH;

@property (nonatomic , strong) UIView * windowTipBackView;

@property (nonatomic , strong) PolicyStatusModel * policyStatusModel;

//显示挣点蒙板 显示后设置为no
@property (nonatomic , assign) BOOL moneyTipViewIsHave;
//显示订单添加蒙板 显示后设置为no
@property (nonatomic , assign) BOOL homeTipeViewIsHave;

//h5页面
@property (nonatomic, copy) NSArray *h5s;

//广告背景弹出的view
@property (nonatomic , strong) UIView * adverticeBackV;//是弹出广告层的背景view
@property (nonatomic , strong) UIView * adverticeBlackBackV;//弹出广告层的黑色的背景view
@property (nonatomic , strong) AdverticePopView * adverticePopV;//弹出的广告view
@property (nonatomic , assign) BOOL adverticePopVBool;//控制动画实现的控制
@property (nonatomic , assign) BOOL adverticeLookVBool;//控制页面显示或消失是否隐藏广告弹层

@property (nonatomic , copy) NSArray * popH5List;

//@property (nonatomic, strong) OneWayMgr *oneWayMgr;

@end

@implementation HomePageViewController
#pragma mark --- view cycle

- (void)dealloc{
    
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.title = @"首页";
    
    [self.view addSubview:self.tabelView];
    [self earnImageViewAnimation];
    [[NSNotificationCenter defaultCenter] addObserver:self.tabelView selector:@selector(reloadData) name:@"Messages_Update" object:nil];
    self.refreshMgr = [RefreshMgr sharedInstance];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateMoney) name:REFRESH_MONEY object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateReward) name:REFRESH_REWARD object:nil];
    
    self.adverticePopVBool = YES;
    [self createAdverticePopView];
}

#pragma mark - 创建弹出广告
- (void)createAdverticePopView
{
    __weak __typeof(self) wself = self;

    UIWindow * mainWindow = [UIApplication sharedApplication].delegate.window;
    [mainWindow addSubview:self.adverticeBackV];
    [self.adverticeBackV addSubview:self.adverticeBlackBackV];
    [self.adverticeBackV addSubview:self.adverticePopV];
    
    [self.adverticeBackV setHidden:YES];
    
    [self.adverticeBlackBackV addTapSingleAction:^(UITapGestureRecognizer *recognizer) {
        [wself adverticePopVBtnClick];
    }];
        
}
#pragma mark - 创建首页弹出广告的取消按钮事件
- (void)adverticePopVBtnClick
{
    __weak __typeof(self) wself = self;
    [UIView animateWithDuration:0.5 animations:^{
        [wself.adverticePopV setCenter:(wself.adverticePopVBool ? CGPointMake(__MAIN_WIDTH - 30, 55) : CGPointMake(__MAIN_WIDTH / 2, __MAIN_HEIGHT / 2))];
        if(!wself.adverticePopVBool)[wself.adverticeBackV setHidden: NO];
        if(!wself.adverticePopVBool)[wself.adverticePopV setHidden: NO];
        [wself.adverticePopV setTransform:(wself.adverticePopVBool ? CGAffineTransformMakeScale(0.01, 0.01) : CGAffineTransformMakeScale(1, 1))];
        [wself.adverticeBlackBackV setHidden:wself.adverticePopVBool];
    }completion:^(BOOL finished) {
        [wself.adverticePopV setHidden:wself.adverticePopVBool];
        [wself.adverticeBackV setHidden:wself.adverticePopVBool];
        wself.adverticePopVBool = !wself.adverticePopVBool;
    }];
}
-(void)updateMoney{
    [self.tabelView reloadData];
}
-(void)updateReward{

//    if (self.refreshMgr.refreshReward.newReward > 0)[self createTipViewCorver];
    if(self.windowTipBackView)[self.windowTipBackView setHidden:((self.policyStatusModel.policyStatusBool || self.refreshMgr.refreshReward.newReward > 0) ? NO : YES)];
    if (self.refreshMgr.refreshReward.newReward > 0) {//有奖励
        self.line.hidden = NO;
        self.earnImageView.hidden = NO;
    }else{//无奖励
        self.line.hidden = YES;
        self.earnImageView.hidden = YES;
    }
}
#pragma mark - 保单数据
- (void)loadPolicyStatusData{
    
    __weak typeof (self) wself = self;
    [[NetHomePage getPolicyStatus]requestSuccess:^(id JSON) {
        wself.policyStatusModel = [[PolicyStatusModel alloc]initWithDic:JSON[@"list"]];
        wself.policyStatus = wself.policyStatusModel.policyStatus;
        wself.premium = wself.policyStatusModel.premium;
        wself.totalScoreMoney = wself.policyStatusModel.totalScoreMoney;
        wself.currScoreModey = wself.policyStatusModel.currScoreModey;
        [wself.tabelView reloadData];
        
//        if(wself.policyStatusModel.policyStatusBool)[self createTipViewCorver];
        if(wself.windowTipBackView)[wself.windowTipBackView setHidden:((wself.policyStatusModel.policyStatusBool || wself.refreshMgr.refreshReward.newReward > 0) ? NO : YES)];
    } failure:^(id JSON) {
        
    }];
}

#pragma mark --等级接口
- (void)loadHomePageLevel{
    
    __weak __typeof(self) wself = self;
    [[NetHomePage getLevelInfo] requestSuccess:^(id JSON){
        wself.number = [JSON objectForKey:@"level"];
        [wself.tabelView reloadData];
    }];
}

#pragma mark --- 领取挣点动画
- (void)earnImageViewAnimation{
    
    self.line = [[[UIView viewWithFrame:CGRectMake(self.view.right - 40, 0, 1, HEIGHT_LINE_VIEW_SMALL)] resetBackgroundColor:COLOR_HEXSTRING(@"#CCCCCC")] setupOnView:self.view];
    self.line.hidden = YES;
    // 领取挣点  (此处要做动画)
    self.earnImageView = [Factory imageViewWithCenter:CGPointMake(self.line.centerX, self.line.bottom + 20) image:ImageNamed(@"Home_get earn") onView:self.view];
    self.earnImageView.userInteractionEnabled = YES;
    self.earnImageView.hidden = YES;
    
    // 注册点击手势
    UITapGestureRecognizer *panGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureAction:)];
    [self.earnImageView addGestureRecognizer:panGesture];
}
#pragma mark - 首页广告
- (void)loadH5Data
{
    __weak __typeof(self) wself = self;
    
    //广告
    [NetAdvertice loadAdverticesWithCode:APP_REWARD_AD success:^(NSArray *list) {
        if(wself.line)
        {
            [wself.line setHeight:(list.count > 0 ? (HEIGHT_ADVERTISE_VIEW + HEICHT_ADVERTISE_VIEW_LINE * 2 + HEIGHT_LINE_VIEW_SMALL) : HEIGHT_LINE_VIEW_SMALL)];
            [wself.earnImageView setCenterY:wself.line.bottom + 20];
        }
        wself.adverticeDataArr = list;
        [wself.tabelView reloadData];
        if(wself.adverticeView)
        {
            [wself.adverticeView setHeight:(list.count > 0 ? HEIGHT_ADVERTISE_VIEW : 0)];
            wself.adverticeView.slideImages = [NSMutableArray arrayWithArray:list];
            [wself.adverticeView reloadScrollViewAndPageController:wself.adverticeView.frame PageControllerFrame:CGRectMake(wself.adverticeView.width - 20 * list.count - 15 * __MAIN_RATIO_375, wself.adverticeView.height  - 20 ,20 * list.count, 18)];
            [wself.adverticeView startSlide];
            wself.adverticeView.clickedWithIndex= ^(int index){//index第几张图
                AdverticePageModel * model = list[index];
                
                [[StatisticsMgr sharedInstance] addClickID:[NSString stringWithFormat:@"%@-%@",APP_REWARD_AD,model.title] description:@"首页顶部广告条"];
                
                [SCREEN viewController:wself pushWebViewControllerWithModel:model];
            };
        }
    } fail:^{
        if(wself.adverticeView && wself.adverticeDataArr.count == 0)[wself.adverticeView setHeight:0];
        [wself.tabelView reloadData];
    }];
    
    //h5
    [NetAdvertice loadAdverticesWithCode:APP_HOMEPAGE_H5 success:^(NSArray *list) {
        wself.h5s = list;
    } fail:nil];
    
    //弹出层广告
    [NetAdvertice loadAdverticesWithCode:APP_POP_AD success:^(NSArray *list) {
        if ((list.count > 0)) {
            wself.popH5List = list;
            [wself navSetupRightImageName:@"homeAdvPopVGitImge" action:^{
                [wself adverticePopVBtnClick];
            }];
            
            if(wself.adverticePopVBool)[wself.adverticeBackV setHidden:NO];
            
            AdverticePageModel * model = list[0];
            [wself.adverticePopV raloadImageUrl:model.img withClick:^{
                [wself adverticePopVBtnClick];
                [[StatisticsMgr sharedInstance] addClickID:[NSString stringWithFormat:@"%@-%@",APP_POP_AD,model.title] description:@"首页弹出层广告"];
                [SCREEN viewController:wself presentWebViewControllerWithModel:model close:nil];
            }];
            
        }
    } fail:^{
        if(wself.popH5List.count == 0){
            [wself.adverticeBackV setHidden:YES];
            [wself navSetupRightTitle:@"" action:nil];
        }else
        {
            [wself navSetupRightImageName:@"" action:^{
                [wself adverticePopVBtnClick];
            }];
            if(wself.adverticePopVBool)[wself.adverticeBackV setHidden:NO];
        }
    }];

}
#pragma mark --- 处理界面跳转 和 上传图片的逻辑
- (void)dealWithUploadAndJump{
    __weak __typeof(self) wself = self;
    // 上传图片
    self.headPagecell.headDetailView.UploadClick = ^(UIButton *sender){
//        [wself createQuestion];
        [UmengMgr event:ICZ_Upload_policy];
        CommitInfoViewController *commitVC = [[CommitInfoViewController alloc] initWithTableRefreshType:TYPE_TABLE_REFRESH_NONE];
        commitVC.paramsDic = @{@"icz_imgType":@"policy", @"img_title":@"", @"img_describe":@"请确保图片清晰"};
        [wself presentViewController:[UINavigationController navigationControllerWithRootViewController:commitVC] animated:YES completion:nil];
        commitVC.UploadSuccess = ^(NSString *url){
            [[NetHomePage bindingPolicyPicWithImageURL:url] requestSuccess:^(id JSON) {
                [wself loadPolicyStatusData];
            } failure:^(id JSON) {
                
            }];
        };
    };
    // 跳转到问号的H5界面
//    self.headPagecell.headDetailView.JumpClick = ^(){

//       [wself createQuestion];
        
//    };
    self.headPagecell.headDetailView.JumpRemainMoney = ^(){

        [UmengMgr event:ICZ_Left_Point];
        [wself.navigationController pushViewController:[[[MoneyTabViewController alloc] init] navSetupBackItemWithIdentification:BACK_ICON_TITLE] animated:YES];
    };
    
}
#pragma mark - 创建弹出的问号提示层
/*
 - (void)createQuestion
{
    UIWindow *mainWindow = [UIApplication sharedApplication].delegate.window;
    UIView * backView = [[[UIView viewWithFrame:mainWindow.bounds] resetBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.8]] setupOnView:mainWindow];
    CGFloat labelX= 22 * __MAIN_RATIO_375;
    NSArray * titleArr = @[@"最大抵扣车险=您上传保单的商业险*10%",@"若未上传保单:",@"最大抵扣车险=2000元的商业险*10%",@"注:抵扣车险包括2015年部分老用户的剩余挣点"];
    CGFloat cancelButtonAndLabelY = 73 * __MAIN_RATIO_375;
    UILabel * titleLabel = [Factory labelWithFrame:CGRectMake(labelX ,( backView.height - 30 - (18 * __MAIN_RATIO_375 + 22 * __MAIN_RATIO_375 + 24 * __MAIN_RATIO_375 + 25 * __MAIN_RATIO_375 + cancelButtonAndLabelY + ImageNamed(@"homeAlertViewCancelImge").size.height) - 20 * titleArr.count ) / 2 , __MAIN_WIDTH - labelX * 2, 30) font:FONT_DEFAULT_Light(20) text:@"可抵扣保费" textColor:[UIColor whiteColor] onView:backView textAlignment:NSTextAlignmentCenter];
    UIView * lineView = [[[UIView viewWithFrame:CGRectMake(labelX, titleLabel.bottom + 22 * __MAIN_RATIO_375, titleLabel.width, 0.5)] resetBackgroundColor:[UIColor whiteColor]] setupOnView:backView];
    CGFloat lastLabelBottom = 0;
    for (int index = 0 ; index < titleArr.count; index ++) {
        CGFloat detailLY = lineView.bottom + 18 * __MAIN_RATIO_375 + 20 * index + (index >= 1 ? 24 * __MAIN_RATIO_375 : 0) + (index >= 3 ? 25 * __MAIN_RATIO_375 : 0);
        [Factory labelWithFrame:CGRectMake(labelX, detailLY, titleLabel.width, 20) font:FONT_DEFAULT_Light(13) text:titleArr[index] textColor:[UIColor whiteColor] onView:backView textAlignment:NSTextAlignmentLeft];
        lastLabelBottom = detailLY + 20;
    }
    [Factory buttonWithCenter:CGPointMake(backView.width / 2, lastLabelBottom + cancelButtonAndLabelY + ImageNamed(@"homeAlertViewCancelImge").size.height / 2) withImage:ImageNamed(@"homeAlertViewCancelImge") click:^{
        [backView removeFromSuperview];
    } onView:backView];
}
 */
#pragma mark --- 红包点击按钮 下拉动画
- (void)panGestureAction:(UITapGestureRecognizer *)pan{
    
    [UmengMgr event:ICZ_GetPoint];
    __weak __typeof(self) wself = self;
    [UIView animateKeyframesWithDuration:1 delay:0 options:0 animations:^{
        
        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 animations:^{
            wself.oldLineViewH = wself.line.height;
            [wself.line setHeight: wself.line.height + 60];
            [wself.earnImageView setCenter: CGPointMake(wself.view.right - 40, wself.line.bottom + 20)];
        }];
        
        [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
            [wself.line setHeight: wself.oldLineViewH];
            wself.earnImageView.center = CGPointMake(wself.view.right - 40, wself.line.bottom + 20);
        }];
        
    } completion:^(BOOL finished) {
        [HomePageMgr getAllRewardFinish:^(NSInteger money) {
            
            wself.headPagecell.headDetailView.FinishAnimation();

            [NSTimer scheduledTimerWithTimeInterval:2 block:^{
                
                [wself.refreshMgr.refreshReward startRefreshWithTimeInterval:0];
                [wself.refreshMgr.refreshMoney startRefreshWithTimeInterval:0];
                [wself loadPolicyStatusData];
                
                [wself showGetMoneyTips:money];
                
            } repeats:NO];
        } fail:^{
            [AlertMgr showShortNoNetworkTextTips:@[@"网络出现问题！"]];
            wself.headPagecell.headDetailView.FinishAnimation();
        }];
        [wself removeIconsAndLine];
        
    }];
}

-(void)showGetMoneyTips:(NSInteger)money{
    HomeMoneyTipsView *tipsV = [[HomeMoneyTipsView alloc] initWithCenter:self.headPagecell.boundsCenter money:money];
    [self.view addSubview:tipsV];
    tipsV.alpha = 0;
    tipsV.top += 10;
    [UIView animateKeyframesWithDuration:1 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
        tipsV.alpha = 1;
        tipsV.top -= 10;
    } completion:^(BOOL finished) {
        [NSTimer scheduledTimerWithTimeInterval:1 block:^{
            [UIView animateWithDuration:1 animations:^{
                tipsV.alpha = 0;
                tipsV.top -= 10;
            } completion:^(BOOL finished) {
                [tipsV removeFromSuperview];
            }];
        } repeats:NO];
    }];
}

- (void)removeIconsAndLine{
    
    self.line.hidden = YES;
    self.earnImageView.hidden = YES;
//    self.line = nil;
//    self.earnImageView = nil;
    
}

#pragma mark --- tableView delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat height = 0.0;
    switch (indexPath.row) {
        case 0:
            // 广告界面
            height = (self.adverticeDataArr.count > 0 ? (HEIGHT_ADVERTISE_VIEW + HEICHT_ADVERTISE_VIEW_LINE * 2) : 0);
            
            break;
        case 1:
            // 指针动画界面
            
            height = [HeadPageTableViewCell heightForCell];
            
            break;
        case 2:
            // 通知界面
            
            // 存在就加上，不存在则  height = 0；
            
            height = ([MessageMgr sharedInstance].nums > 0) ? HEIGHT_NOTIFITION_CELL : 0;
            
            break;
            
        default:

            break;
    }
    
    if (indexPath.row >= cellNumbers) {
        height = [HomePageH5Cell heightForCell];
    }
    
    return height;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return cellNumbers + self.h5s.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString * cellID = [NSString stringWithFormat:@"cell%zd",MIN(indexPath.row, cellNumbers)];
    
    UITableViewCell *cell ;
    
    switch (indexPath.row) {
        case 0:
            // 广告界面
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
                [cell addSubview:self.adverticeView];
                
            }
            cell.backgroundColor = [UIColor clearColor];
            [self.adverticeView setHidden:!(self.adverticeDataArr.count > 0)];

            break;
        case 1:
            // 指针动画界面
            if (!self.headPagecell) {
                cell = [[HeadPageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
                self.headPagecell = (HeadPageTableViewCell *)cell;

            }
            cell = self.headPagecell;
            self.headPagecell.headDetailView.status = self.policyStatus;
            self.headPagecell.headDetailView.totalScoreMoney = self.totalScoreMoney;
            self.headPagecell.headDetailView.currScoreModey = self.currScoreModey;
            self.headPagecell.headDetailView.premium = self.premium;
            ((HeadPageTableViewCell *)cell).headDetailView.remainEarn = self.refreshMgr.refreshMoney.currentMoney;
            
            [self dealWithUploadAndJump];

            break;
        case 2:
            // 通知界面
            if (!cell) {
                if ([MessageMgr sharedInstance].nums > 0) {
                    cell = [[HeadNotificationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID withMessage:[MessageMgr sharedInstance].message];
                    
                }else{
                    cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
                }
            }
            break;

        default:

            break;
    }
    
    if (indexPath.row >= cellNumbers) {
        if (!cell) {
            cell = [[HomePageH5Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        ((HomePageH5Cell *)cell).model = self.h5s[indexPath.row - cellNumbers];

    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // 跳转 H5 界面

    
    switch (indexPath.row) {
        case 2:{
            MessageViewController *vc = [[[MessageViewController alloc] initWithTableRefreshType:TYPE_TABLE_REFRESH_PULL_UP] navSetupBackItemWithIdentification:BACK_ICON_TITLE];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
    
    if (indexPath.row >= cellNumbers) {
        AdverticePageModel *model = self.h5s[indexPath.row - cellNumbers];
        [[StatisticsMgr sharedInstance] addClickID:[NSString stringWithFormat:@"%@-%@",APP_HOMEPAGE_H5,model.title] description:@"首页H5页面"];
        [SCREEN viewController:self pushWebViewControllerWithModel:model];
    }
}

#pragma mark --- setter   and   getter
- (UITableView *)tabelView{
    if (_tabelView == nil) {
        _tabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, __MAIN_WIDTH, __MAIN_HEIGHT_64_TABBAR) style:UITableViewStylePlain];
        _tabelView.delegate = self;
        _tabelView.dataSource = self;
        _tabelView.separatorColor = [UIColor clearColor];
        _tabelView.backgroundColor = [Theme backGroundColor];
    }
    return _tabelView;
}

- (void)setNumber:(NSString *)number{
    _number = number;
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.adverticeLookVBool = YES;
    [self loadH5Data];
    [self loadPolicyStatusData];
    [self loadHomePageLevel];
    [UmengMgr event:ICZ_Index];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.refreshMgr.refreshMoney startRefreshWithTimeInterval:0];
    [self.refreshMgr.refreshReward startRefreshWithTimeInterval:0];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.refreshMgr.refreshMoney stopRefresh];
    [self.refreshMgr.refreshReward stopRefresh];
    [self.adverticeView endSlide];
    self.adverticeLookVBool = NO;
    [self.adverticeBackV setHidden:YES];
}

#pragma mark - 创建头部广告view
-(AdverticePageView *)adverticeView{
    if (!_adverticeView) {
       
        _adverticeView = [[AdverticePageView alloc]initWithFrame:CGRectMake(0, HEICHT_ADVERTISE_VIEW_LINE, __MAIN_WIDTH , HEIGHT_ADVERTISE_VIEW)];
        _adverticeView.isNetworkImage = YES;
        _adverticeView.shufflingTimer = 5;
        _adverticeView.backgroundColor=[Theme backGroundColor];
        
        [[[UIView viewWithFrame:CGRectMake(0, - HEICHT_ADVERTISE_VIEW_LINE, __MAIN_WIDTH, HEICHT_ADVERTISE_VIEW_LINE)] resetBackgroundColor:[Theme lineColor]] setupOnView:_adverticeView];
        [[[UIView viewWithFrame:CGRectMake(0, _adverticeView.height, __MAIN_WIDTH, HEICHT_ADVERTISE_VIEW_LINE)] resetBackgroundColor:[Theme lineColor]] setupOnView:_adverticeView];
    }
    return _adverticeView;
}
- (UIView *)adverticeBlackBackV
{
    if (!_adverticeBlackBackV) {
        _adverticeBlackBackV = [[UIView viewWithFrame:__MAIN_BOUND] resetBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.6]];
    }
    return _adverticeBlackBackV;
}
- (AdverticePopView *)adverticePopV
{
    if (!_adverticePopV) {
        CGFloat popVW = 324 * __MAIN_RATIO_375;
        CGFloat popVH = 415 * __MAIN_RATIO_375;
        _adverticePopV = [[AdverticePopView alloc]initWithFrame:CGRectMake( (__MAIN_WIDTH - popVW) / 2, (__MAIN_HEIGHT - popVH) / 2, popVW , popVH )];
    }
    return _adverticePopV;
}
- (UIView *)adverticeBackV
{
    if(!_adverticeBackV)
    {
        _adverticeBackV = [[UIView viewWithFrame:__MAIN_BOUND] resetBackgroundColor:[UIColor clearColor]];
    }
    return _adverticeBackV;
}

//-(OneWayMgr *)oneWayMgr{
//    if (!_oneWayMgr) {
//        _oneWayMgr = [[OneWayMgr alloc] init];
//    }
//    return _oneWayMgr;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
